﻿using Entities;
using EntityManage;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ChatClient
{
    public partial class FormAddFriend : Form
    {
        public FormAddFriend()
        {
            InitializeComponent();
        }
        public FormAddFriend(int id, string name)
        : this()
        {
            _id = id;
            _myname = name;
        }

        private int _id;
        string _myname;
        Users user;
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtID.Text == "")
            {
                return;
            }
            var user = UserManager.GetUsers(int.Parse(txtID.Text));
            if (user == null)
            {
                MessageBox.Show("用户不存在");
                return;
            }
            else
            {
                txtNickName.Text = user.NickName;
                this.user = new Users();
                this.user.ID = user.ID;
                this.user.NickName = user.NickName;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (user != null)
            {
                if (UserManager.AddFriend(_id, _myname, user.ID, user.NickName))
                {
                    MessageBox.Show("添加成功");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
        }
    }
}
